package com.leecode.exercise;


/**
 * @Author: shubin_yao
 * @Date: 2022/04/03/10:36
 * @Description:
 */

class TreeNodeDemo {

    public static void main(String[] args) {
        TreeNodeDemo treeNodeDemo = new TreeNodeDemo();
        TreeNode treeNode = new TreeNode(1, new TreeNode(2), new TreeNode(3));
        boolean b = treeNodeDemo.hasPathSum(treeNode, 4);
        System.out.println(b);
    }


    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }
        if (root.left == null && root.right == null) {
            return root.val == targetSum;
        }
        return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val) ;
    }
}